import os,sys
import glob
import numpy as np
import shutil
import Image
def renameToJPG(dir):
    files = glob.glob(dir)
    for file in files:
        #print(file)
        os.rename(file, file + ".jpg")
def renameCount(dir):
    count = 89
    files = glob.glob(dir + "*")
    for file in files:
        os.rename(file, dir + "child_" + str(count))
        count = count + 1
def resize(file, width, height):
    if(os.path.isdir(file)):
        # print(file)
        files = glob.glob(file + "/*")
        for f in files:
            resize(f, width, height)
        return
    img1 = Image.open(file)
    img2 = img1.resize((width, height), Image.BILINEAR) 
    img2.save("save/" + os.path.basename(file))
def f(**kwargs):
    if 'labels' not in kwargs:
        raise "To train age estimation, need to pass 'labels' parameter!"
    else:
        labels = kwargs['labels']
    print(labels)
def replaceCommawithAnd(file):
    f = open(file, 'r')
    lines = f.readlines()
    x = []
    for line in lines:
        y = line.replace(",", '&')
        x.append(y)
    wr = open("/home/loai/Desktop/temp.txt", 'w')
    wr.writelines(x)
    wr.close()
def YoussofTestVideoAymanAndMeScaryVeryFunny():
    a = os.listdir("/media/SONY_MOBILE")
    print(a)
    print("done")
    
def removeFilesWithSubstring(dir, substr):
    files = os.listdir(dir)
    for f in files:
        if substr in f:
            os.remove(os.path.join(dir, f))
def findFileContains(dir, substr):
    if(os.path.isdir(dir)):
        for f in os.listdir(dir):
            findFileContains(os.path.join(dir, f), substr)
    else :
        f = open(dir, 'r')
        lines = f.readlines()
        for line in lines:
            if substr in line:
                print("Found in " + dir)
def t(a,b=5):
    b+=1
    return b
def difference(dir1,dir2):
    dic=dict([(x.replace(' ',''),x) for x in os.listdir(dir1)])
    f1=[a.replace(' ','') for a in os.listdir(dir1)]
    f2=[a.replace(' ','') for a in os.listdir(dir2)]
  
    x=[a for a in f1 if a not in f2 and "NoName" not in a]
    y=[dic[a] for a in x]
    dst="/home/loai/Desktop/Temp"
    for f in [os.path.join(dir1,a) for a in y]:
        shutil.copy(f, dst)
    return y
def check(g1,g2):
    d1=open(g1)
    d2=open(g2)
    f1=d1.readlines()
    f2=d2.readlines()
    count=1
    for x,y in zip(f1,f2):
        count+=1
        if x !=y :
            print x,y,count
if __name__ == "__main__":
    # param1= sys.argv[1]
    #param2=sys.argv[2] 
    param1="/home/loai/Desktop/Algebra.tokens"
    param2="/home/loai/Programming/Java/NewEclipse/workspace/compiler/Sample.out"
    check(param1,param2)
